package homework;

public class NumProbability {
	
	public double setNumProbability(int start,int end,Double probability, int  target) throws Exception{
		int m=1000;
		int count=0;
		if (start > end) {
			throw new Exception("end must larger than start");
		}else if (target<end && target > start){
			for (int i = 0; i < m; i++) {
				int a=(int)((Math.random()*(end-start+1)) + start);
				double b=Math.random();
				if (b<(probability-(double)(1/(end-start+1)))) {
					a=target;
				}
				if (a==target) {
					count++;
				}
				
			}	
		}else {
			throw new Exception("target must between start and end");
		}
		return (double)(count/m);	
	}

}
